package com.examples.font;

import org.eclipse.swt.SWT;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.events.SelectionListener;
import org.eclipse.swt.graphics.Color;
import org.eclipse.swt.graphics.Font;
import org.eclipse.swt.graphics.FontData;
import org.eclipse.swt.graphics.RGB;
import org.eclipse.swt.layout.RowLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.FontDialog;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Text;

public class FontDialogBasic {

	public static void main(String[] args) {
		final Display d = Display.getDefault();
		final Shell s = new Shell(d);
		
		s.setLayout(new RowLayout());

		final Text t = new Text(s, SWT.BORDER);
		Button b = new Button(s, SWT.PUSH);
		b.setText("Change Font");

		b.addSelectionListener(new SelectionListener() {

			@SuppressWarnings("deprecation")
			@Override
			public void widgetSelected(SelectionEvent e) {
				FontDialog fontDialog = new FontDialog(s, SWT.NONE);
				fontDialog.setText("Select Font");
				fontDialog.setRGB(new RGB(255, 0, 0));
				
				FontData defaultFontData = new FontData("Microsoft Sans Serif", 20, SWT.ITALIC);
				fontDialog.setFontData(defaultFontData);
				
				fontDialog.open();
				t.setFont(new Font(d, fontDialog.getFontData()));
				t.setBackground(new Color(d, fontDialog.getRGB()));
			}

			@Override
			public void widgetDefaultSelected(SelectionEvent e) {
			}
		});
		s.open();
		
		while(!s.isDisposed()){
			if(!d.readAndDispatch()){
				d.sleep();
			}
		}
	}
}
